/* The code examples copyrighted by Nokia Corporation that are included to
 * this material are licensed to you under following MIT-style License:
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <GConfItem>

#include "GConfExample.hpp"

const char* DFooKey = "/apps/basic-gconf-app_qt/foo";
const char* DBarKey = "/apps/basic-gconf-app_qt/bar";
const char* DBazKey = "/apps/basic-gconf-app_qt/baz";

GConfExample::GConfExample(QObject *rootObject)
{
	fooItem = new GConfItem(DFooKey, this);
	barItem = new GConfItem(DBarKey, this);
	bazItem = new GConfItem(DBazKey, this);
	// call matching ValueChanged function whenever gconf value is changed
	QObject::connect(fooItem, SIGNAL(valueChanged()), this, SLOT(FooValueChanged()));
	QObject::connect(barItem, SIGNAL(valueChanged()), this, SLOT(BarValueChanged()));
	QObject::connect(bazItem, SIGNAL(valueChanged()), this, SLOT(BazValueChanged()));
	// Connect signals for updating Text items from C++
	QObject::connect(this, SIGNAL(fooData(QVariant)), rootObject, SLOT(updateFooData(QVariant)));
	QObject::connect(this, SIGNAL(barData(QVariant)), rootObject, SLOT(updateBarData(QVariant)));
	QObject::connect(this, SIGNAL(bazData(QVariant)), rootObject, SLOT(updateBazData(QVariant)));
	// Update Text items to current value
	FooValueChanged();
	BarValueChanged();
	BazValueChanged();
}


GConfExample::~GConfExample()
{
}

// These get called whenever user wants to set Text item text
void GConfExample::SetFooText(const QString& text)
{
	fooItem->set(QVariant(text));
}


void GConfExample::SetBarText(const QString& text)
{
	barItem->set(QVariant(text));
}


void GConfExample::SetBazText(const QString& text)
{
	bazItem->set(QVariant(text));
}

// These slots are triggered whenever current value changes.
// Emits a signal that sets the matching text item to current value.
void GConfExample::FooValueChanged()
{
	emit fooData(QVariant(fooItem->value().toString()));
}


void GConfExample::BarValueChanged()
{
	emit barData(QVariant(barItem->value().toString()));
}


void GConfExample::BazValueChanged()
{
	emit bazData(QVariant(bazItem->value().toString()));
}
